package com.appleword.biz.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.appleword.common.annotation.Log;
import com.appleword.common.core.controller.BaseController;
import com.appleword.common.core.domain.AjaxResult;
import com.appleword.common.enums.BusinessType;
import com.appleword.biz.book.domain.ApplewordBook;
import com.appleword.biz.book.service.IApplewordBookService;
import com.appleword.common.utils.poi.ExcelUtil;
import com.appleword.common.core.page.TableDataInfo;

/**
 * 书Controller
 * 
 * @author apple
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/book/book")
public class ApplewordBookController extends BaseController
{
    @Autowired
    private IApplewordBookService applewordBookService;

    /**
     * 查询书列表
     */
    @PreAuthorize("@ss.hasPermi('book:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplewordBook applewordBook)
    {
        startPage();
        List<ApplewordBook> list = applewordBookService.selectApplewordBookList(applewordBook);
        return getDataTable(list);
    }

    /**
     * 导出书列表
     */
    @PreAuthorize("@ss.hasPermi('book:book:export')")
    @Log(title = "书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplewordBook applewordBook)
    {
        List<ApplewordBook> list = applewordBookService.selectApplewordBookList(applewordBook);
        ExcelUtil<ApplewordBook> util = new ExcelUtil<ApplewordBook>(ApplewordBook.class);
        util.exportExcel(response, list, "书数据");
    }

    /**
     * 获取书详细信息
     */
    @PreAuthorize("@ss.hasPermi('book:book:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applewordBookService.selectApplewordBookById(id));
    }

    /**
     * 新增书
     */
    @PreAuthorize("@ss.hasPermi('book:book:add')")
    @Log(title = "书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplewordBook applewordBook)
    {
        return toAjax(applewordBookService.insertApplewordBook(applewordBook));
    }

    /**
     * 修改书
     */
    @PreAuthorize("@ss.hasPermi('book:book:edit')")
    @Log(title = "书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplewordBook applewordBook)
    {
        return toAjax(applewordBookService.updateApplewordBook(applewordBook));
    }

    /**
     * 删除书
     */
    @PreAuthorize("@ss.hasPermi('book:book:remove')")
    @Log(title = "书", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applewordBookService.deleteApplewordBookByIds(ids));
    }
}